home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 22 / epsonrx.zip / EPSONRX.ASM next >
Assembly Source File  |  1987-06-07  |  16KB  |  560 lines

  1.  
  2. NAME    EPSONRX
  3.     PAGE    50,130
  4.     TITLE    EPSONRX.COM    RITARI/MACK '87    
  5. ;
  6. ;******************************************************************************
  7. ;
  8. ;EPSONRX.COM    -Setup Utility for Epson printer
  9. ;    from an idea by Douglas Ritari; PC Tech J., Sep 84, p 79
  10. ;
  11. ;    Modified by Joseph MACK
  12. ;    Dept Chemistry, UMBC
  13. ;    5401 Wilkens Ave
  14. ;    Catonsville,MD,21228
  15. ;    (301)-455-3292
  16. ;    Jun '87
  17. ;
  18. ;******************************************************************************
  19. ;
  20. ;prog constants
  21.         cr    equ    13
  22.         lf    equ    10
  23. ;
  24. ;
  25. MAIN    SEGMENT    PARA    PUBLIC    'CODE'
  26.         ORG    100H
  27.         
  28. START    PROC    FAR
  29. ;
  30.         ASSUME    CS:MAIN
  31.         ASSUME    DS:MAIN
  32.         ASSUME    SS:MAIN
  33.         ASSUME    ES:MAIN
  34.         db        "EPSONRX.COM Joe MACK Jun 87"        ;Notice in early code
  35. ;PUBLICS------------------------------------------------
  36. ;numbers
  37. public    sw,testpr,num_digits,fd_oor,parm
  38. ;procedures
  39. public    sstart, start, alpha_entry, buzzer, default, disp_char, escape, hex_err_msg, hexmath, hexon, printer, prmsg,
  40. ;general locations
  41. public    alph_hex, bit_3_ok, bit_5_ok, b_loop, end_math, end_parm, hex_ok, math2, out_test, out_of_range, second_digit, search, search_end, slash, success, sw_on
  42. ;parms
  43. public    parm_a, parm_b, parm_c, parm_d, parm_e, parm_f, parm_g, parm_h, parm_i, parm_j, parm_k, parm_l, parm_m, parm_n, parm_o, parm_p, parm_q, parm_r, parm_s, parm_t, parm_u, parm_v, parm_w, parm_x
  44. ;errors
  45. public     error_3, error_4, error_5, prn_err_bit_3, prn_err_bit_5    
  46. ;msgs
  47. public    success_msg, prog_name, d_msg, inkey_msg, err_msg_1, err_msg_2, err_msg_3, err_msg_4, err_msg_5, err_msg_6, err_msg_8
  48. ;
  49. ;--------------------------------------------
  50. ;
  51.         JMP    SSTART    ;Jump to real start of prog
  52. ;
  53. ;************************INITIALISE DATA VARIABLES*****************************
  54. ;constants initialised at load time, not at execution time
  55. ;
  56. SW            DB    0    ;Switch for HEX '/' seq.-either '0' or 'FFH'
  57. SIXTEEN        DB    16    ;the number '16' used in hex conversion -mul
  58. TESTPR        DB    0    ;Switch to test if any output was produced
  59. NUM_DIGITS    DB    0    ;Number of hex digits produced-'0' or '1'
  60. FD_OOR        DB    0    ;first digit out of range
  61. HEX            DB    0    ;hex accumulator
  62. PARM        DB    0    ;Move param to here -1 byte at a time
  63. ;
  64. ;******************************************************************************
  65. ; BEGIN PROG- SAVE RETURN ADDRESS FOR DOS
  66. ;******************************************************************************
  67. ;
  68. SSTART:
  69.         PUSH    DS    ;Save PSP Seg address
  70.         MOV    AX,0
  71.         PUSH    AX    ;Save return address offset (PSP+0)
  72. ;
  73. ;***************CHECK PRINTER***************************************************
  74. ;
  75.         PUSH    AX
  76.         PUSH    DX        ;save registers
  77.         MOV    AH,02    ;read port
  78.         MOV    DX,0        ;port 00=printer#1
  79.         INT    17H        ;read status
  80.         TEST    AH,8H    ;bit 3 on?-I/O error
  81.         JZ    BIT_3_OK
  82.         LEA    DX,prn_err_bit_3
  83.         CALL    PRMSG
  84.         POP    DX
  85.         POP    AX
  86.         RET            ;pop registers and exit to DOS
  87. BIT_3_OK:TEST    AH,20H    ;bit 5 on?-out of paper
  88.         JZ    BIT_5_OK
  89.         LEA    DX,prn_err_bit_5
  90.         CALL    PRMSG
  91.         POP    DX
  92.         POP    AX
  93.         RET            ;exit to DOS
  94. BIT_5_OK:POP     DX
  95.         POP    AX
  96. ;    
  97. ;got here if printer OK
  98. ;
  99. ;******************MOVE COUNT OF CHARACTERS INTO PARM AREA********************
  100. ;
  101.         MOV    SI,80H        ;Source string offset (within PSP)
  102.         MOV    DI,OFFSET PARM    ;dest string offset
  103.         CLD                ;Set 'forward' string operations
  104.         MOVSB            ;move # of params entered into 'PARM' variable
  105.         DEC    DI
  106. ;
  107. ;*******************SET UP PARM FIELD'S POINTERS*******************************
  108. ;
  109.         MOV    AL,PARM        ;Put number of char. in parm into AL register
  110.         MOV    CX,AX        ;      "                          CX
  111.         MOV    BX,OFFSET PARM    ;point to parms base address
  112.         CMP    CX,0            ;were no parms entered ?
  113.         JNE    SEARCH        ;param found
  114.         CALL    DEFAULT        ;end of search, no parms found-send defaults
  115.         RET                ;end program, return to DOS,(PSP and offset POPed)
  116. ;
  117. ;******************************************************************************
  118. ; PARMS WERE ENTERED- SEARCH FOR AND PROCESS PARAMETERS
  119. ;******************************************************************************
  120. ;
  121. SEARCH:    MOVSB            ;read in parm from prog.seg. prefix
  122.         DEC    DI            
  123.         MOV    AL,[BX]        ;move next parm to input reg
  124.         CMP    AL,' '        ;blank?
  125.         JE    SEARCH_END    ;ignore
  126.         CMP    AL,','        ;comma?
  127.         JE    SEARCH_END    ;ignore
  128. ;
  129.         CMP    AL,'a'        ;UC/lc?
  130.         JL    ALPH_HEX        ;do not modify this letter if lower than 'a'
  131.         AND    AL,223        ;reduce by 32, uncaps==>caps
  132. ;
  133. ALPH_HEX:CMP    SW,0            ;=1 hex sequence on,=0 off
  134.         JE    SLASH        ;expects alph input
  135.         CALL    HEXON        ;expects hex input
  136.         JMP    SEARCH_END
  137. ;
  138. ;got here if hex not on
  139. ;
  140. SLASH:    CMP    AL,'/'        ;hex sequence begun?
  141.         JE    SW_ON
  142.         CALL    ALPHA_ENTRY    ;expects alphabetic input
  143.         JMP    SEARCH_END    ;look for next char
  144. ;
  145. SW_ON:    MOV    SW,1            ;turn on hex sequence
  146. SEARCH_END:    LOOP SEARCH    ;get more input
  147. ;
  148. ;******************************************************************************
  149. ;Get here if no more parms available. Check for unpaired hex digits
  150. ;******************************************************************************
  151. ;
  152.         CMP    NUM_DIGITS,0    ;unpaired hexcodes? =0 paired, =1 unpaired?
  153.         JE    OUT_TEST
  154.         PUSH    DX
  155.         LEA    DX,err_msg_6    ;unpaired digits
  156.         CALL    PRMSG    
  157.         POP    DX
  158. ;
  159.         CALL    DISP_CHAR        ;ouput unpaired digit
  160. ;
  161. OUT_TEST:    CMP    TESTPR,1    ;=0 no valid output
  162.         JE    SUCCESS
  163.         CALL    DEFAULT
  164. ;
  165. SUCCESS:    PUSH    DX
  166.         LEA    DX,success_msg
  167.         CALL    PRMSG
  168.         POP    DX
  169. ;
  170.         RET                ; to DOS
  171. ;
  172. ;*************End of prog proc*************************************************
  173. ;
  174. START    ENDP        ;end main
  175. ;
  176. ;******************************************************************************
  177. ;
  178. ;        ORG    200H
  179. ;
  180. PRMSG    PROC NEAR
  181. ;int 21h scrambles AX, I didn't expect that, so save AX
  182.         PUSH    AX
  183.         MOV    AH,9        ;print string instruction
  184.          INT    21H        ;print DX msg
  185.         POP    AX
  186.         RET
  187. PRMSG    ENDP
  188. ;
  189. ;*************Escape routine, send escape code to printer**********************
  190. ;
  191. ESCAPE    PROC    NEAR
  192.         PUSH    AX            ;save potential char to be printed on stack
  193.         MOV    AL,1BH        ;escape char to out reg.
  194.         CALL    PRINTER        
  195.         POP    AX
  196.         CALL    PRINTER        ;send saved char
  197.         RET
  198. ESCAPE    ENDP
  199. ;
  200. ;*************printing s/r- all done from here**********************************
  201. ;
  202. ;send char in AL to printer
  203. ;
  204. PRINTER     PROC    NEAR
  205.         MOV    TESTPR,1        ;valid output has been produced
  206.         MOV    DX,0            ;set register for printer output INT
  207.         MOV    AH,0            ;"
  208.         INT    17H            ;call printer driver in BIOS
  209.         RET
  210. PRINTER    ENDP
  211. ;
  212. ;*************Edit for valid hex numbers ***************************************
  213. ;
  214. HEXON    PROC NEAR            ;tests for valid hex digit,
  215.                         ;if OK calls HEXMATH,    otherwise sends errors
  216.         SUB    AL,30H        ;convert from ASCII to rel numbers (30H=0D)
  217.         JC    OUT_OF_RANGE    ;carry flag set, char<30H=0D, invalid param
  218.         CMP    AL,9            ;check for digit >9
  219.         JBE    HEX_OK        ;valid number, jump to math routine call
  220.         SUB    AL,7            ;convert from ASCII to hex A-F
  221.         CMP    AL,0FH
  222.         JA    OUT_OF_RANGE    ;error if hex>0FH
  223. ;
  224. HEX_OK:    CALL    HEXMATH        ;convert input param to hex
  225.         RET                ;to main
  226. ;
  227. ;Get here if hex parm not in range 0-0FH
  228. ;
  229. OUT_OF_RANGE:    CMP    NUM_DIGITS,0    ;=0 if first digit
  230.         JNE    SECOND_DIGIT
  231.         INC    NUM_DIGITS
  232.         MOV    FD_OOR,1        ;first digit out of range
  233.         CALL    HEX_ERR_MSG
  234.         RET
  235. ;
  236. SECOND_DIGIT:
  237.         CALL    HEX_ERR_MSG
  238.         MOV    SW,0            ;reset switches
  239.         MOV    NUM_DIGITS,0
  240.         MOV    FD_OOR,0
  241.         RET
  242. ;
  243. HEXON    ENDP
  244. ;
  245. ;********convert input params to hex numbers*********************************************************************
  246. ;
  247. HEXMATH    PROC    NEAR
  248.         CMP    NUM_DIGITS,0    ;0= 1st ,1= 2nd number
  249.         JNE    MATH2        ;jump and process second number
  250.         MUL    SIXTEEN        ;mult 1st number by 16
  251.         MOV    HEX,AL        ;clear & restore result in hex
  252.         INC    NUM_DIGITS        ;1st number processed
  253.         RET
  254. ;
  255. MATH2:    CMP    FD_OOR,1        ;0= valid
  256.         JE    END_MATH
  257.         ADD    AL,HEX        ;second hex number, total the two digits
  258.         MOV    NUM_DIGITS,0        ;clear digit var for further use
  259.         CALL PRINTER        ;send hex number in AL to printer
  260. ;
  261. END_MATH:MOV    FD_OOR,0        ;reset switches
  262.         MOV    SW,0
  263.         RET
  264. ;
  265. HEXMATH    ENDP
  266. ;
  267. ;********hex error messages****************************************************
  268. ;
  269. HEX_ERR_MSG    PROC    NEAR
  270. ;
  271.         PUSH    AX        ;int 21h scrambles AL
  272.         PUSH DX
  273.         LEA    DX,err_msg_1    ;invalid hex param
  274.         CALL    PRMSG
  275.         POP    DX
  276.         POP    AX
  277. ;
  278.         CALL    DISP_CHAR    ;output orig invalid char
  279. ;
  280.         PUSH    DX
  281.         LEA    DX,err_msg_4    ;parm ignored, execution continued
  282.         CALL    PRMSG
  283.         POP    DX
  284. ;
  285.         RET
  286. ;
  287. HEX_ERR_MSG    ENDP
  288. ;
  289. ;******************************************************************************
  290. ;
  291. DISP_CHAR    PROC    NEAR
  292. ;    
  293.         MOV    AL,[BX]        ;recover orig char
  294.         PUSH    BX            ;save registers before outputting char
  295.         PUSH    CX
  296.         XOR    BX,BX        ;clear BX, sets page to 0
  297.         MOV    CX,1            ;1 char to display
  298.         MOV    AH,0AH        ;int fn 10D
  299.         INT    10H            ;display char at cursor posn
  300.         POP    CX
  301.         POP    BX
  302. ;
  303.         RET
  304. ;    
  305. DISP_CHAR    ENDP
  306. ;
  307. ;******************************************************************************
  308. ;
  309. ;*************BUZZER s/r*******************************************************
  310. ;sounds buzzer
  311. ;
  312. BUZZER    PROC    NEAR
  313.         MOV    AL,07        ;buzzer param
  314.         CALL    PRINTER
  315.         RET
  316. BUZZER    ENDP
  317. ;
  318. ;*************DEFAULT S/R*******************************************************
  319. ;
  320. ;changes TESTPR to 1 through call to PRINTER, so PGMEND detects successfull output
  321. ;No params found, set default,
  322. ;
  323. ;*******************************************************************************
  324. ;
  325. ;        ORG    300H
  326. ;
  327. DEFAULT    PROC    NEAR
  328. ;           
  329.         MOV    AL,07H        ;beep
  330.         CALL    PRINTER
  331. ;
  332. ;        CALL    PRINTER
  333. ;
  334. ;******************************************************************************
  335. ;If no param codes entered then give param codes.
  336. ;Notify of default execution and type.
  337. ;Defaults are set before displaying message.
  338. ;If print echoed, will see default font on printer.
  339. ;******************************************************************************
  340. ;
  341.          PUSH    DX            ;save DX
  342. ;        LEA    DX,prog_name    ;prog name
  343. ;        CALL    PRMSG        ;print message
  344.         LEA    DX,d_msg        ;default params send to screen
  345.         CALL    PRMSG    
  346. ;
  347.         LEA    DX,inkey_msg    ;msg for "inkey to continue"
  348.         CALL    PRMSG
  349.         POP     DX
  350. ;
  351.         MOV     AH,0        ;wait for key press
  352.         INT    16H        ;call keyboard_io at F000:E82E, wait for char
  353.         POP    AX        ;ignore char in AL
  354. ;
  355.         PUSH DX
  356.         LEA    DX,p_msg    ;param codes available send to screen
  357.         CALL    PRMSG
  358.         POP    DX        ;recover DX
  359. ;
  360.         RET
  361. DEFAULT    ENDP
  362. ;
  363. ;******************************************************************************
  364. ;PARAMETER DECISION AND ACTION
  365. ;******************************************************************************
  366. ;
  367. ;        ORG    400H
  368. ;
  369. ALPHA_ENTRY    PROC    NEAR
  370. ;
  371. PARM_A:
  372. PARM_B:    CMP    AL,'B'        ;buzzer?
  373.         JNE    PARM_C
  374.         MOV    AL,07H
  375. ;do loop
  376.         PUSH    CX            ;currently being used for number of parms
  377.         MOV    CX,04H        
  378. B_LOOP:    CALL    PRINTER        ;need long beep
  379.         LOOP    B_LOOP
  380.         POP    CX
  381.         JMP    END_PARM
  382. ;
  383. PARM_C:    CMP    AL,'C'        ;condense?
  384.         JNE    PARM_D
  385.         MOV    AL,0FH
  386.         CALL    PRINTER        ;condensed doesn't need escape
  387.         JMP    END_PARM
  388. ;
  389. PARM_D:    CMP    AL,'D'        ;double strike?
  390.         JNE    PARM_E
  391.         MOV    AL,'G'
  392.         CALL    ESCAPE
  393.         JMP     END_PARM
  394. ;
  395. PARM_E:    CMP    AL,'E'        ;elite? 12/"
  396.         JNE    PARM_F
  397.         MOV    AL,'M'        ;elite (12/")
  398.         CALL    ESCAPE
  399.         JMP    END_PARM
  400. ;    
  401. PARM_F:    CMP    AL,'F'        ;form feed?
  402.         JNE    PARM_G
  403.         MOV    AL,0CH        ;advance paper to top of form
  404.         CALL    PRINTER
  405.         JMP    END_PARM
  406. ;
  407. PARM_G:
  408. PARM_H:
  409. PARM_I:    CMP    AL,'I'        ;italics
  410.         JNE    PARM_J
  411.         MOV    AL,'4'
  412.         CALL    ESCAPE
  413.         JMP    END_PARM
  414.  
  415. PARM_J:
  416. PARM_K:
  417. PARM_L:    CMP    AL,'L'        ;line feed
  418.         JNE    PARM_M
  419.         MOV    AL,0AH
  420.         CALL    PRINTER
  421.         JMP     END_PARM
  422. ;
  423. PARM_M:    CMP    AL,'M'        ;parm to 'eMphasise'?
  424.         JNE    PARM_N
  425.         MOV    AL,45H        ;Epson code for eMphasised font
  426.         CALL    ESCAPE
  427.         JMP    END_PARM
  428. ;
  429. PARM_N:
  430. PARM_O:
  431. PARM_P:    CMP     AL,'P'        ;Pica- if do reset get new TOF
  432.         JNE    PARM_Q        ;instead turn of all print width functions
  433.         MOV    AL,'P'        ;elite off
  434.         CALL    ESCAPE
  435.         MOV    AL,18H        ;compressed off
  436.         CALL    PRINTER
  437.         MOV    AL,'W'        ;wide off
  438.         CALL    ESCAPE
  439.         MOV    AL,00H        ;off
  440.         CALL    PRINTER
  441.         JMP    END_PARM
  442. ;
  443. PARM_Q:
  444. PARM_R:    CMP    AL,'R'        ;reset?
  445.         JNE    PARM_S
  446.         MOV    AL,'@'        ;reset= cancell all modes, reset to logical TOF
  447.         CALL    ESCAPE        ;pica =10 char per inch
  448.         JMP     END_PARM
  449. ;
  450. PARM_S:    
  451. PARM_T:    CMP    AL,'T'        ;set tabs?
  452.         JNE    PARM_U
  453.         MOV    AL,'e'
  454.         CALL    ESCAPE
  455.         MOV    AL,05H        ;tabs at repeats of 5
  456.         CALL    PRINTER
  457.         JMP    END_PARM
  458. ;
  459. PARM_U:    CMP    AL,'U'        ;underline
  460.         JNE    PARM_V
  461.         MOV    AL,'-'
  462.         CALL    ESCAPE
  463.         MOV    AL,01H        ;set "on"
  464.         CALL    PRINTER
  465.         JMP    END_PARM
  466. ;
  467. PARM_V:
  468. PARM_W:    CMP    AL,'W'        ;wide
  469.         JNE    PARM_X
  470.         MOV    AL,'W'
  471.         CALL    ESCAPE
  472.         MOV    AL,01H        ;set "on"
  473.         CALL    PRINTER
  474.         JMP    END_PARM
  475. ;
  476. PARM_X:    
  477. PARM_Y:
  478. PARM_Z:    JMP    ERROR_3
  479. END_PARM:    RET                ;exit s/r 
  480. ;
  481. ;Invalid alphabetical parameter found
  482. ;
  483. ERROR_3:    PUSH    DX            ;write error message
  484.         LEA    DX,err_msg_3    ;invalid parm msg
  485.         CALL    PRMSG
  486.         POP    DX
  487. ;
  488.         CALL    DISP_CHAR
  489. ;
  490. ERROR_4:    PUSH    DX
  491.         LEA    DX,err_msg_4    ;parm ignored, execution continued
  492.         CALL    PRMSG
  493. ERROR_5:    LEA    DX,err_msg_5    ;where to find valid parm list
  494.         CALL    PRMSG
  495.         POP    DX
  496.         RET                ;to main, 
  497. ;
  498. ALPHA_ENTRY    ENDP
  499. ;
  500. ;******************************************************************************
  501. ;Program data
  502. ;
  503. ;
  504. ;        ORG    600H
  505. ;
  506. ;
  507.     p_msg    db    "Command Format:-Epson [/xx] [a][b]",cr,lf,lf
  508.             db    "/xx     -heX input (must be paired)                                      ",cr,lf
  509.             db    "                                          ***************************",cr,lf
  510.             db    "B   -Buzzer on printer                    *   Conflict Priorities   *",cr,lf
  511.             db    "C   -Condensed                            *                         *",cr,lf
  512.             db    "D   -Double Strike                        * Elite                   *",cr,lf
  513.             db    "E   -Elite 12/inch                        *     \                   *",cr,lf
  514.             db    "F   -Form feed                            *      Emphasised         *",cr,lf
  515.             db    "I   -Italic                               *             \           *",cr,lf
  516.             db    "L   -Line feed                            *            Compressed   *",cr,lf
  517.             db    "M   -eMphasized                           *                    \    *",cr,lf
  518.             db    "P   -Pica, 12/inch                        *                    Pica *",cr,lf
  519.             db    "R   -Reset = clear, TOF, Pica,            ***************************",cr,lf
  520.             db    "T   -Tabs at mulitiple of 5                                          ",cr,lf
  521.             db    "U   -Underline                                                       ",cr,lf
  522.             db    "W   -Wide                                                            ",cr,lf
  523.             db    "/   -Hex on for 2 chars. Blanks, commas ignored on command line.     ",cr,lf
  524.             db    "UC or lc or mixed are OK. Hex and alphabetical mixed is OK.          ",cr,lf
  525.             db    "Some commands will undo previous commands.                           ",cr,lf,"$"
  526. ;
  527. ;******************************************************************************
  528. ;
  529. success_msg        db    cr,lf
  530.                 db    "EPSONRX.COM       Ritari/Mack 1987",cr,lf,"$"
  531. ;
  532. prog_name        db    cr,lf
  533.                 db    "EPSONRX.COM     written  by Douglas Ritari, 1983",cr,lf
  534.                 db    "                modified by Joseph  Mack  , 1987",cr,lf,lf,"$"
  535. ;
  536. d_msg            db    cr,lf
  537.                 db    "These current default codes have been sent to the printer:",,
  538. ;
  539. ;put command(s) parameters, for current default, into next line, between double quotes 
  540. ;
  541.                 db    "B"
  542.                 db    cr,lf,lf,"$"
  543. ;
  544.     inkey_msg        db    cr,lf,"Press any key to continue."                ,cr,lf,"$"
  545.     err_msg_1        db    cr,lf,"Invalid hex digit found(ie not 0-0FH):$"    ,
  546.     err_msg_2        db    cr,lf,"No action taken.",cr,lf                ,"$"
  547.     err_msg_3        db    cr,lf,"Invalid alphabetical character:$"        ,
  548.     err_msg_4        db    cr,lf,"Character ignored, execution continued.$"
  549.     err_msg_5        db    cr,lf,"Valid parameters available by returning to DOS and typing <EPSONRX>.",cr,lf,"$"
  550.     err_msg_6        db    cr,lf,"Unpaired hex parameter:$"                ,
  551.     err_msg_8        db    cr,lf,"Character ignored, execution terminated."    ,cr,lf,"$"
  552.     prn_err_bit_3    db    cr,lf,"printer I/O error."                    ,cr,lf,"$"
  553.     prn_err_bit_5    db    cr,lf,"printer out of paper."                    ,cr,lf,"$"        
  554. ;
  555. ;******************************************************************************
  556. ;
  557. ;
  558. MAIN    ENDS
  559.         END    START
  560.